/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * <p>Project: jse2302 - Stream02
 * <p>Powered by webrx On 2023-06-29 09:47:02
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Stream02 {
    public static void main(String[] args) {
        //建立流
        IntStream is1 = IntStream.rangeClosed(1, 5);
        is1.forEach(System.out::println);

        //建立5个元素的随机double流 ()->.5
        Stream<Double> ss = Stream.generate(Math::random).limit(5);
        ss.forEach(System.out::println);

        Stream<String> sss = Stream.of("a", "b", "c");
        Stream<String> ss2 = "a\r\nb\r\n".lines();

        IntStream stream = Arrays.stream(new int[]{1, 2, 3});

        Stream<Integer> sss34 = List.of(1, 2, 3).stream();

        System.out.println(IntStream.rangeClosed(1, 100).sum());


        Random rand = new Random();
        var is2 = IntStream.generate(() -> rand.nextInt(1, 101)).limit(10);
        int sum = is2.sum();
        System.out.println(sum);

        //is2.forEach(e -> {
        //    System.out.printf("%02d ", e);
        //});


        Stream<Integer> s =  Stream.iterate(0, t -> t + 2).skip(2).limit(5);
        s.forEach(System.out::println);

    }
}
